{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Workflow Manager\n",
    "\n",
    "The Workflow Manager Notebook provides a centralized location for preparing and running calculations according to the high-throughput workflow used by the NIST Interatomic Potentials Repository."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Settings\n",
    "\n",
    "This section allows for specific run settings to be managed and selected."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from copy import deepcopy\n",
    "from multiprocessing import Pool\n",
    "from pathlib import Path\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "import iprPy\n",
    "\n",
    "from iprPy.workflow import prepare, multi_runners, process, fix_lammps_versions\n",
    "\n",
    "from iprPy.tools import aslist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.1 Machine-based settings\n",
    "\n",
    "This is where the LAMMPS and MPI commands to use on different machines can be defined.\n",
    "\n",
    "Note: some potential versions do not work with the most current LAMMPS due to changes either in the parameter file structure or how LAMMPS reads the files. There *should* be new versions of these potential parameter files in the repository, with the old versions marked as either \"retracted\" or \"superseded\". Should you wish to test the older versions, you will need to install and specify older LAMMPS commands and specify potential_status to be \"all\" when preparing the calculations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "allcommands = {}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "My desktop settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "commands = allcommands['desktop'] = {}\n",
    "\n",
    "# mpi_command should list all settings except use {np_per_runner} for the variable number of processors per runner\n",
    "commands['mpi_command'] = 'mpiexec -localonly {np_per_runner}' \n",
    "\n",
    "# lammps_command should be most current LAMMPS on your computer - at least after 30 Oct 2019\n",
    "commands['lammps_command'] = 'E:/LAMMPS/2020-03-03/bin/lmp_mpi'\n",
    "\n",
    "########## Optional old LAMMPS versions #############\n",
    "\n",
    "# SNAP version 1 needs LAMMPS between 8 Oct 2014 and 30 May 2017\n",
    "commands['lammps_command_snap_1'] = 'E:/LAMMPS/2017-01-27/bin/lmp_mpi'\n",
    "\n",
    "# SNAP version 2 needs LAMMPS between 3 Dec 2018 and 12 June 2019\n",
    "commands['lammps_command_snap_2'] = 'E:/LAMMPS/2019-06-05/bin/lmp_mpi'\n",
    "\n",
    "# Old needs LAMMPS before 30 Oct 2019\n",
    "commands['lammps_command_old'] = 'E:/LAMMPS/2019-06-05/bin/lmp_mpi'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "My laptop settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "commands = allcommands['laptop'] = {}\n",
    "\n",
    "# mpi_command should list all settings except use {np_per_runner} for the variable number of processors per runner\n",
    "commands['mpi_command'] = 'C:/Program Files/MPICH2/bin/mpiexec -localonly {np_per_runner}' \n",
    "\n",
    "# lammps_command should be most current LAMMPS on your computer - at least after 30 Oct 2019\n",
    "commands['lammps_command'] = 'lmp_mpi'\n",
    "\n",
    "########## Optional old LAMMPS versions #############\n",
    "\n",
    "# SNAP version 1 needs LAMMPS between 8 Oct 2014 and 30 May 2017\n",
    "commands['lammps_command_snap_1'] = 'C:/Program Files/LAMMPS/2017-01-27/bin/lmp_mpi'\n",
    "\n",
    "# SNAP version 2 needs LAMMPS between 3 Dec 2018 and 12 June 2019\n",
    "commands['lammps_command_snap_2'] = 'C:/Program Files/LAMMPS/2019-06-05/bin/lmp_mpi'\n",
    "\n",
    "# Old needs LAMMPS before 30 Oct 2019\n",
    "commands['lammps_command_old'] = 'C:/Program Files/LAMMPS/2019-06-05/bin/lmp_mpi'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Ruth cluster settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "commands = allcommands['ruth'] = {}\n",
    "\n",
    "# mpi_command should list all settings except use {np_per_runner} for the variable number of processors per runner\n",
    "commands['mpi_command'] = '/cluster/deb9/bin/mpirun -n {np_per_runner}' \n",
    "\n",
    "# lammps_command should be most current LAMMPS on your computer - at least after 30 Oct 2019\n",
    "commands['lammps_command'] = 'lmp_mpi'\n",
    "\n",
    "########## Optional old LAMMPS versions #############\n",
    "\n",
    "# SNAP version 1 needs LAMMPS between 8 Oct 2014 and 30 May 2017\n",
    "#commands['lammps_command_snap_1'] =\n",
    "\n",
    "# SNAP version 2 needs LAMMPS between 3 Dec 2018 and 12 June 2019\n",
    "#commands['lammps_command_snap_2'] = \n",
    "\n",
    "# Old needs LAMMPS before 30 Oct 2019\n",
    "#commands['lammps_command_old'] = "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.2 Default database settings\n",
    "\n",
    "In case you want to use the same settings for multiple calculations\n",
    "\n",
    "- __database_name__ is the name of the database to load and use, i.e. where the calculation records are stored.\n",
    "- __run_directory_name__ is the name of the run directory to load and use, i.e. where the calculations are prepared to, and executed from if num_runners is > 0. \n",
    "- __num_runners__ is the number of runners to start up after preparing a calculation, i.e. how many calculations to run at the same time.  Setting this to 0 will only prepare calculations allowing runners to be started up externally.\n",
    "- __np_per_runner__ is the number of cores/processors each runner is allowed, i.e. number of cores to use for an mpi call for each calculation.\n",
    "- __run_location__ specifies the machine on which the calculations will be performed on. If num_runners = 0, calculations can be prepared on one system and copied over to another for running. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "default_database_name = 'master'\n",
    "default_run_directory_name = 'master_4'\n",
    "default_num_runners = 6\n",
    "default_np_per_runner = 1\n",
    "default_run_location = 'desktop'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- --\n",
    "\n",
    "## 2. Structure-free calculations\n",
    "\n",
    "These are the calculations that evaluate energies computed from the potentials that are not associated with crystal structures."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# This is a list of bad implementations that should ALWAYS issue errors\n",
    "bad_imps = [\n",
    "    # Invalid parameter files\n",
    "    '1990--Ackland-G-J--Cu--LAMMPS--ipr1',\n",
    "    '2009--Zhakhovskii-V-V--Al--LAMMPS--ipr1',\n",
    "    '2009--Zhakhovskii-V-V--Au--LAMMPS--ipr1',\n",
    "    '2015--Broqvist-P--Ce-O--LAMMPS--ipr1',\n",
    "    \n",
    "    # Incorrect MEAM parameters in JSON\n",
    "    '2009--Kim-H-K--Fe-Ti-C--LAMMPS--ipr1',\n",
    "    '2012--Jelinek-B--Al-Si-Mg-Cu-Fe--LAMMPS--ipr1',\n",
    "    '2013--Gao-H--AgTaO3--LAMMPS--ipr1',\n",
    "    '2014--Liyanage-L-S-I--Fe-C--LAMMPS--ipr1',\n",
    "    '2015--Ko-W-S--Ni-Ti--LAMMPS--ipr1',\n",
    "    '2015--Pascuet-M-I--Al-U--LAMMPS--ipr1',\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 Diatom scan"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = default_run_directory_name\n",
    "num_runners = default_num_runners\n",
    "np_per_runner = default_np_per_runner\n",
    "run_location = default_run_location\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Set commands for this machine\n",
    "commands = allcommands[run_location]\n",
    "global_kwargs['lammps_command'] = commands['lammps_command']\n",
    "if np_per_runner > 1:\n",
    "    global_kwargs['mpi_command'] = commands['mpi_command'].format(np_per_runner=np_per_runner)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "#global_kwargs['prototype_id'] = 'A1--Cu--fcc'\n",
    "global_kwargs['maximum_r'] = '10.0',\n",
    "global_kwargs['number_of_steps_r'] = '500'\n",
    "\n",
    "# Potential-based modifiers\n",
    "pot_kwargs = {}\n",
    "pot_kwargs['status'] = 'all'\n",
    "pot_kwargs['id'] = ['2021--Wang-G--Au-Rh--LAMMPS--ipr1']\n",
    "#pot_kwargs['pair_style'] = ['eam', 'eam/alloy', 'eam/fs', 'eam/cd']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing diatom_scan\n",
      "894 existing calculation records found\n",
      "3 record combinations to check\n",
      "0 new records to prepare\n",
      "\n",
      "Starting 6 runners in master_4 for master\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "    \n",
    "# Prepare\n",
    "kwargs = deepcopy(global_kwargs)\n",
    "for key in pot_kwargs:\n",
    "    kwargs[f'potential_{key}'] = pot_kwargs[key]\n",
    "      \n",
    "prepare.diatom_scan.main(database_name, run_directory_name, **kwargs)\n",
    "\n",
    "# Fix LAMMPS versions if needed\n",
    "fix_lammps_versions(run_directory_name, commands)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "database = iprPy.load_database(database_name)\n",
    "records_df = database.get_records_df(style='calculation_diatom_scan')\n",
    "records_df = records_df[~records_df.potential_LAMMPS_id.isin(bad_imps)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([], dtype=object)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.unique(records_df[records_df.status=='error'].potential_LAMMPS_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.2 Isolated atom"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = default_run_directory_name\n",
    "num_runners = default_num_runners\n",
    "np_per_runner = default_np_per_runner\n",
    "run_location = default_run_location\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Set commands for this machine\n",
    "global_kwargs['lammps_command'] = allcommands[run_location]['lammps_command']\n",
    "if np_per_runner > 1:\n",
    "    global_kwargs['mpi_command'] = allcommands[run_location]['mpi_command'].format(np_per_runner=np_per_runner)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "\n",
    "\n",
    "# Potential-based modifiers\n",
    "pot_kwargs = {}\n",
    "pot_kwargs['status'] = 'all'\n",
    "pot_kwargs['id'] = ['2021--Wang-G--Au-Rh--LAMMPS--ipr1']\n",
    "#pot_kwargs['pair_style'] = ['eam', 'eam/alloy', 'eam/fs', 'eam/cd']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing isolated_atom\n",
      "331 existing calculation records found\n",
      "1 record combinations to check\n",
      "1 new records to prepare\n",
      "\n",
      "Starting 6 runners in master_4 for master\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "    \n",
    "# Prepare\n",
    "kwargs = deepcopy(global_kwargs)\n",
    "for key in pot_kwargs:\n",
    "    kwargs[f'intpot_{key}'] = pot_kwargs[key]\n",
    "\n",
    "prepare.isolated_atom.main(database_name, run_directory_name, **kwargs)\n",
    "\n",
    "# Fix LAMMPS versions if needed\n",
    "fix_lammps_versions(run_directory_name, commands)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "database = iprPy.load_database(database_name)\n",
    "records_df = database.get_records_df(style='calculation_isolated_atom')\n",
    "records_df = records_df[~records_df.potential_LAMMPS_id.isin(bad_imps)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([], dtype=object)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.unique(records_df[records_df.status=='error'].potential_LAMMPS_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- - -\n",
    "\n",
    "## 3. Structure relaxation calculations\n",
    "\n",
    "These are the calculations used to identify the relaxed structures on a per-potential basis. This set of calculations comprises a mini-workflow all to itself:\n",
    "\n",
    "- E_vs_r_scan runs first\n",
    "- relax_box, relax_dynamic are then prepared from E_vs_r_scan results and DFT structures\n",
    "- relax_static are then prepared from E_vs_r_scan, relax_dynamic results and DFT structures\n",
    "- crystal_space_group are then prepared from relax_box, relax_static results, DFT structures and prototypes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1 E_vs_r_scan"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = default_run_directory_name\n",
    "num_runners = default_num_runners\n",
    "np_per_runner = default_np_per_runner\n",
    "run_location = default_run_location\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Set commands for this machine\n",
    "global_kwargs['lammps_command'] = allcommands[run_location]['lammps_command']\n",
    "if np_per_runner > 1:\n",
    "    global_kwargs['mpi_command'] = allcommands[run_location]['mpi_command'].format(np_per_runner=np_per_runner)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "#global_kwargs['prototype_id'] = 'A1--Cu--fcc'\n",
    "\n",
    "# Potential-based modifiers\n",
    "pot_kwargs = {}\n",
    "pot_kwargs['status'] = 'all'\n",
    "pot_kwargs['id'] = ['2021--Wang-G--Au-Rh--LAMMPS--ipr1']\n",
    "#pot_kwargs['pair_style'] = ['eam', 'eam/alloy', 'eam/fs', 'eam/cd']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing E_vs_r_scan\n",
      "12306 existing calculation records found\n",
      "No bops to give\n",
      "Preparing E_vs_r_scan\n",
      "12306 existing calculation records found\n",
      "36 record combinations to check\n",
      "36 new records to prepare\n",
      "\n",
      "Starting 6 runners in master_4 for master\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "\n",
    "# Prepare\n",
    "kwargs = deepcopy(global_kwargs)\n",
    "for key in pot_kwargs:\n",
    "    kwargs[f'prototype_potential_{key}'] = pot_kwargs[key]\n",
    "\n",
    "# Prepare bop potentials\n",
    "pair_style = kwargs.pop('prototype_potential_pair_style', None)\n",
    "if pair_style is None or 'bop' in pair_style:\n",
    "    try:\n",
    "        prepare.E_vs_r_scan.bop(database_name, run_directory_name, **kwargs)\n",
    "    except:\n",
    "        print('No bops to give')\n",
    "\n",
    "# Prepare other potentials\n",
    "if pair_style is not None:\n",
    "    kwargs['prototype_potential_pair_style'] = pair_style\n",
    "prepare.E_vs_r_scan.main(database_name, run_directory_name, **kwargs)\n",
    "\n",
    "# Fix LAMMPS versions if needed\n",
    "fix_lammps_versions(run_directory_name, commands)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "database = iprPy.load_database(database_name)\n",
    "records_df = database.get_records_df(style='calculation_E_vs_r_scan')\n",
    "records_df = records_df[~records_df.potential_LAMMPS_id.isin(bad_imps)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([], dtype=object)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.unique(records_df[records_df.status=='error'].potential_LAMMPS_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2 relax box"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = default_run_directory_name\n",
    "num_runners = default_num_runners\n",
    "np_per_runner = default_np_per_runner\n",
    "run_location = default_run_location\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Set commands for this machine\n",
    "global_kwargs['lammps_command'] = allcommands[run_location]['lammps_command']\n",
    "if np_per_runner > 1:\n",
    "    global_kwargs['mpi_command'] = allcommands[run_location]['mpi_command'].format(np_per_runner=np_per_runner)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "#global_kwargs['prototype_id'] = 'A1--Cu--fcc'\n",
    "\n",
    "# Potential-based modifiers\n",
    "pot_kwargs = {}\n",
    "pot_kwargs['status'] = 'all'\n",
    "pot_kwargs['id'] = ['2021--Wang-G--Au-Rh--LAMMPS--ipr1']\n",
    "#pot_kwargs['pair_style'] = ['eam', 'eam/alloy', 'eam/fs', 'eam/cd']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing relax_box\n",
      "43940 existing calculation records found\n",
      "57 record combinations to check\n",
      "57 new records to prepare\n",
      "\n",
      "Starting 6 runners in master_4 for master\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "\n",
    "# Prepare\n",
    "kwargs = deepcopy(global_kwargs)\n",
    "for key in pot_kwargs:\n",
    "    kwargs[f'reference_potential_{key}'] = pot_kwargs[key] \n",
    "    kwargs[f'parent_potential_{key}'] = pot_kwargs[key]\n",
    "\n",
    "prepare.relax_box.main(database_name, run_directory_name, **kwargs)\n",
    "\n",
    "# Fix LAMMPS versions if needed\n",
    "fix_lammps_versions(run_directory_name, commands)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "database = iprPy.load_database(database_name)\n",
    "records_df = database.get_records_df(style='calculation_relax_box')\n",
    "records_df = records_df[~records_df.potential_LAMMPS_id.isin(bad_imps)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  File \"e:\\python-packages\\atomman\\atomman\\core\\ElasticConstants.py\", line 113, in Cij\n",
      "    assert value.max() > 0.0, 'Cij values not valid'\n",
      "AssertionError: Cij values not valid\n",
      "\n",
      "  File \"C:\\Users\\lmh1\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\numpy\\linalg\\linalg.py\", line 97, in _raise_linalgerror_singular\n",
      "    raise LinAlgError(\"Singular matrix\")\n",
      "numpy.linalg.LinAlgError: Singular matrix\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 172, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 176, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 178, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 180, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 182, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 184, in relax_box\n",
      "    raise RuntimeError('Divergence: cohesive energy is 0')\n",
      "RuntimeError: Divergence: cohesive energy is 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 218, in relax_box\n",
      "    raise RuntimeError('Failed to converge after 100 cycles')\n",
      "RuntimeError: Failed to converge after 100 cycles\n",
      "\n",
      "  File \"e:\\python-packages\\atomman\\atomman\\core\\ElasticConstants.py\", line 113, in Cij\n",
      "    assert value.max() > 0.0, 'Cij values not valid'\n",
      "AssertionError: Cij values not valid\n",
      "\n",
      "  File \"C:\\Users\\lmh1\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\numpy\\linalg\\linalg.py\", line 97, in _raise_linalgerror_singular\n",
      "    raise LinAlgError(\"Singular matrix\")\n",
      "numpy.linalg.LinAlgError: Singular matrix\n",
      "\n",
      "  File \"calc_relax_box.py\", line 368, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 173, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 175, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 177, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 179, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 181, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 183, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 219, in relax_box\n",
      "    raise RuntimeError('Failed to converge after 100 cycles')\n",
      "RuntimeError: Failed to converge after 100 cycles\n",
      "\n",
      "Neighbor list builds = 0\n",
      "Dangerous builds = 0\n",
      "Changing box ...\n",
      "\n",
      "    raise LammpsError(e.output.decode('UTF-8'))\n",
      "atomman.lammps.LammpsError: Incorrect element names in EAM potential file (../pair_eam_alloy.cpp:152)\n",
      "Last command: pair_coeff * * 1998--Meyer-R--Fe--ipr-1\\Fe_MeyerEntel.eam Fe\n",
      "\n",
      "  File \"e:\\python-packages\\atomman\\atomman\\lammps\\run.py\", line 112, in run\n",
      "    raise LammpsError(e.output.decode('UTF-8'))\n",
      "atomman.lammps.LammpsError\n",
      "\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "Neighs:    1.15105e+06 ave 1.15105e+06 max 1.15105e+06 min\n",
      "Histogram: 1 0 0 0 0 0 0\n",
      "\n",
      "Per MPI rank memory allocation (min/avg/max) = 346.7 | 346.7 | 346.7 Mbytes\n",
      "Step Lx Ly Lz Yz Xz Xy Pxx Pyy Pzz Pyz Pxz Pxy v_peatom PotEng \n",
      "       0 2.4114950016264e+01 2.0884539995564e+01 3.7459616587625e+01 0.0000\n",
      "\n",
      "  File \"e:\\python-packages\\atomman\\atomman\\lammps\\run.py\", line 112, in run\n",
      "    raise LammpsError(e.output.decode('UTF-8'))\n",
      "atomman.lammps.LammpsError\n",
      "\n",
      "Per MPI rank memory allocation (min/avg/max) = 4.204 | 4.204 | 4.204 Mbytes\n",
      "Step Lx Ly Lz Yz Xz Xy Pxx Pyy Pzz Pyz Pxz Pxy v_peatom PotEng \n",
      "       0 3.1504337665231e+01 3.1504337665231e+01 3.1504337665231e+01 0.0000000000000e+00 0.00000000000\n",
      "\n",
      "  File \"e:\\python-packages\\atomman\\atomman\\core\\ElasticConstants.py\", line 113, in Cij\n",
      "    assert value.max() > 0.0, 'Cij values not valid'\n",
      "AssertionError: Cij values not valid\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 172, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 176, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 180, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 182, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 172, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 176, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 178, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"e:\\python-packages\\atomman\\atomman\\core\\ElasticConstants.py\", line 113, in Cij\n",
      "    assert value.max() > 0.0, 'Cij values not valid'\n",
      "AssertionError: Cij values not valid\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 172, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 178, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 182, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 176, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 178, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 182, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"e:\\python-packages\\atomman\\atomman\\core\\ElasticConstants.py\", line 113, in Cij\n",
      "    assert value.max() > 0.0, 'Cij values not valid'\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AssertionError: Cij values not valid\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 178, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 178, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 367, in calc_cij\n",
      "    raise RuntimeError('Divergence of box dimensions to <= 0')\n",
      "RuntimeError: Divergence of box dimensions to <= 0\n",
      "\n",
      "  File \"calc_relax_box.py\", line 174, in relax_box\n",
      "    raise RuntimeError('Divergence of box dimensions')\n",
      "RuntimeError: Divergence of box dimensions\n",
      "\n",
      "  File \"calc_relax_box.py\", line 218, in relax_box\n",
      "    raise RuntimeError('Failed to converge after 100 cycles')\n",
      "RuntimeError: Failed to converge after 100 cycles\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "  Time step     : 0.001\n",
      "\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "  Time step     : 0.001\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "  Time step     : 0.001\n",
      "\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "  Time step     : 0.001\n",
      "\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "  Time step     : 0.001\n",
      "\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "  Time step     : 0.001\n",
      "\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "  Time step     : 0.001\n",
      "\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "  Time step     : 0.001\n",
      "\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "  Time step     : 0.001\n",
      "\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "  Time step     : 0.001\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:156)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:156)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:156)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:156)\n",
      "Last command: run 0\n",
      "\n",
      "ERROR on proc 0: Not enough space for bonds! total=196520 allocated=160177\n",
      " (../reaxc_reset_tools.cpp:151)\n",
      "Last command: run 0\n",
      "\n",
      "ERROR on proc 0: Not enough space for bonds! total=243712 allocated=242760\n",
      " (../reaxc_reset_tools.cpp:151)\n",
      "Last command: run 0\n",
      "\n",
      "ERROR on proc 0: Not enough space for bonds! total=433920 allocated=431640\n",
      " (../reaxc_reset_tools.cpp:151)\n",
      "Last command: run 0\n",
      "\n",
      "ERROR on proc 0: Not enough space for bonds! total=302600 allocated=244290\n",
      " (../reaxc_reset_tools.cpp:151)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Failed to allocate 840432324 bytes for array qeq:H.jlist (../memory.cpp:64)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_full_bin_atomonly.cpp:90)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_full_bin_ghost.cpp:151)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_full_bin_ghost.cpp:151)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_full_bin_ghost.cpp:151)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_full_bin_ghost.cpp:151)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newton_tri.cpp:130)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_full_bin_atomonly.cpp:90)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newton_tri.cpp:130)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_full_bin_ghost.cpp:151)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_full_bin_ghost.cpp:151)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_full_bin_atomonly.cpp:90)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n",
      "  Time step     : 0.001\n",
      "ERROR on proc 0: Neighbor list overflow, boost neigh_modify one (../npair_half_bin_newtoff_ghost.cpp:157)\n",
      "Last command: run 0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for error in np.unique(records_df[records_df.status=='error'].error):\n",
    "    print('\\n'.join(error.strip().split('\\n')[-3:]))\n",
    "    print()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3 relax dynamic"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = default_run_directory_name\n",
    "num_runners = default_num_runners\n",
    "np_per_runner = default_np_per_runner\n",
    "run_location = default_run_location\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Set commands for this machine\n",
    "global_kwargs['lammps_command'] = allcommands[run_location]['lammps_command']\n",
    "if np_per_runner > 1:\n",
    "    global_kwargs['mpi_command'] = allcommands[run_location]['mpi_command'].format(np_per_runner=np_per_runner)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "#global_kwargs['prototype_id'] = 'A1--Cu--fcc'\n",
    "\n",
    "# Potential-based modifiers\n",
    "pot_kwargs = {}\n",
    "pot_kwargs['status'] = 'all'\n",
    "pot_kwargs['id'] = ['2021--Wang-G--Au-Rh--LAMMPS--ipr1']\n",
    "#pot_kwargs['pair_style'] = ['eam', 'eam/alloy', 'eam/fs', 'eam/cd']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing relax_dynamic\n",
      "44720 existing calculation records found\n",
      "57 record combinations to check\n",
      "57 new records to prepare\n",
      "\n",
      "Starting 6 runners in master_4 for master\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "\n",
    "# Prepare\n",
    "kwargs = deepcopy(global_kwargs)\n",
    "for key in pot_kwargs:\n",
    "    kwargs[f'reference_potential_{key}'] = pot_kwargs[key]  \n",
    "    kwargs[f'parent_potential_{key}'] = pot_kwargs[key]\n",
    "\n",
    "prepare.relax_dynamic.main(database_name, run_directory_name, **kwargs)\n",
    "\n",
    "# Fix LAMMPS versions if needed\n",
    "fix_lammps_versions(run_directory_name, commands)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.4 relax static"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = default_run_directory_name\n",
    "num_runners = default_num_runners\n",
    "np_per_runner = default_np_per_runner\n",
    "run_location = default_run_location\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Set commands for this machine\n",
    "global_kwargs['lammps_command'] = allcommands[run_location]['lammps_command']\n",
    "if np_per_runner > 1:\n",
    "    global_kwargs['mpi_command'] = allcommands[run_location]['mpi_command'].format(np_per_runner=np_per_runner)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "#global_kwargs['prototype_id'] = 'A1--Cu--fcc'\n",
    "\n",
    "# Potential-based modifiers\n",
    "pot_kwargs = {}\n",
    "pot_kwargs['status'] = 'all'\n",
    "pot_kwargs['id'] = ['2021--Wang-G--Au-Rh--LAMMPS--ipr1']\n",
    "#pot_kwargs['pair_style'] = ['eam', 'eam/alloy', 'eam/fs', 'eam/cd']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing relax_static\n",
      "84714 existing calculation records found\n",
      "57 record combinations to check\n",
      "57 new records to prepare\n",
      "\n",
      "Preparing relax_static\n",
      "84771 existing calculation records found\n",
      "57 record combinations to check\n",
      "57 new records to prepare\n",
      "\n",
      "Starting 6 runners in master_4 for master\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "\n",
    "# Prepare\n",
    "kwargs = deepcopy(global_kwargs)\n",
    "for key in pot_kwargs:\n",
    "    kwargs[f'reference_potential_{key}'] = pot_kwargs[key]   \n",
    "    kwargs[f'parent_potential_{key}'] = pot_kwargs[key]\n",
    "\n",
    "prepare.relax_static.main(database_name, run_directory_name, **kwargs)\n",
    "\n",
    "# Prepare relax_static from relax_dynamic\n",
    "kwargs = deepcopy(global_kwargs)\n",
    "for key in pot_kwargs:\n",
    "    kwargs[f'archive_potential_{key}'] = pot_kwargs[key]\n",
    "\n",
    "if 'parent_family' in kwargs:\n",
    "    kwargs['archive_family'] = kwargs.pop('parent_family')\n",
    "\n",
    "prepare.relax_static.from_dynamic(database_name, run_directory_name, **kwargs)\n",
    "\n",
    "# Fix LAMMPS versions if needed\n",
    "fix_lammps_versions(run_directory_name, commands)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.5 crystal space group"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = default_run_directory_name\n",
    "num_runners = default_num_runners\n",
    "np_per_runner = default_np_per_runner\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Paths to compiled results\n",
    "crystal_match_file = Path('csv', 'reference_prototype_match.csv')\n",
    "all_crystals_file = Path('csv', f'{database_name}_all_crystals.csv')\n",
    "unique_crystals_file = Path('csv', f'{database_name}_unique_crystals.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "#global_kwargs[]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing crystal_space_group\n",
      "86832 existing calculation records found\n",
      "81199 record combinations to check\n",
      "137 new records to prepare\n",
      "\n",
      "Starting 6 runners in master_4 for master\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "\n",
    "# Prepare\n",
    "kwargs = deepcopy(global_kwargs)\n",
    "prepare.crystal_space_group.relax(database_name, run_directory_name, **kwargs)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "43997 calculation_relax_box records found\n",
      " - 43997 are branch main\n",
      "84828 calculation_relax_static records found\n",
      " - 43997 are branch main\n",
      " - 40831 are branch from_dynamic\n",
      "82946 calculation_crystal_space_group records found\n",
      " - 19 are for prototypes\n",
      " - 5751 are for references\n",
      " - 77176 are for calculations\n",
      "5751 references matched to prototypes\n",
      "csv\\master_all_crystals.csv updated\n",
      "59820 untransformed crystals found in the compiled relaxation results\n",
      "59718 relaxed_crystal records found in the database\n",
      " - 102 new results to add\n",
      "59820 relaxed records found\n",
      " - 23952 currently have good standing\n",
      " - 23888 retain good standing\n",
      "csv\\master_unique_crystals.csv updated\n"
     ]
    }
   ],
   "source": [
    "# Call process relaxation results and generate relaxed_crystal records\n",
    "process.relaxed(database_name, crystal_match_file, all_crystals_file, unique_crystals_file)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- - -\n",
    "\n",
    "## 4. Bulk crystal structure properties\n",
    "\n",
    "These are non-defect properties that start from the unique relaxed crystals from section 3."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.1 Elastic constants"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = default_run_directory_name\n",
    "num_runners = default_num_runners\n",
    "np_per_runner = default_np_per_runner\n",
    "run_location = default_run_location\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Set commands for this machine\n",
    "global_kwargs['lammps_command'] = allcommands[run_location]['lammps_command']\n",
    "if np_per_runner > 1:\n",
    "    global_kwargs['mpi_command'] = allcommands[run_location]['mpi_command'].format(np_per_runner=np_per_runner)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "#database = iprPy.load_database(database_name)\n",
    "#pot_df = database.get_records_df(style='potential_LAMMPS')\n",
    "#pot_ids = pot_df.id.tolist()\n",
    "#len(pot_ids)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "#global_kwargs['parent_method'] = 'dynamic'\n",
    "global_kwargs['parent_standing'] = 'good'\n",
    "\n",
    "# Potential-based modifiers\n",
    "pot_kwargs = {}\n",
    "pot_kwargs['status'] = 'all'\n",
    "#pot_kwargs['id'] = pot_ids[150:]\n",
    "pot_kwargs['id'] = ['2021--Wang-G--Au-Rh--LAMMPS--ipr1']\n",
    "#pot_kwargs['pair_style'] = ['eam', 'eam/alloy', 'eam/fs', 'eam/cd']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing elastic_constants_static\n",
      "71550 existing calculation records found\n",
      "114 record combinations to check\n",
      "114 new records to prepare\n",
      "\n",
      "Starting 6 runners in master_4 for master\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "\n",
    "# Prepare\n",
    "kwargs = deepcopy(global_kwargs)\n",
    "for key in pot_kwargs:\n",
    "    kwargs[f'parent_potential_{key}'] = pot_kwargs[key]\n",
    "prepare.elastic_constants_static.main(database_name, run_directory_name, **kwargs)\n",
    "\n",
    "# Fix LAMMPS versions if needed\n",
    "fix_lammps_versions(run_directory_name, commands)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5. Defect properties\n",
    "\n",
    "These are crystalline defect structure properties based on the unique crystal structures identified in section #3."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.1 Free surfaces"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = 'master_3'\n",
    "num_runners = 0\n",
    "np_per_runner = default_np_per_runner\n",
    "run_location = default_run_location\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Set commands for this machine\n",
    "global_kwargs['lammps_command'] = allcommands[run_location]['lammps_command']\n",
    "if np_per_runner > 1:\n",
    "    global_kwargs['mpi_command'] = allcommands[run_location]['mpi_command'].format(np_per_runner=np_per_runner)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "global_kwargs['parent_method'] = 'dynamic'\n",
    "global_kwargs['parent_standing'] = 'good'\n",
    "\n",
    "# Prototype families to generate defects for\n",
    "database = iprPy.load_database(database_name)\n",
    "families = np.unique(database.get_records_df(style='free_surface').family)\n",
    "\n",
    "# Potential-based modifiers\n",
    "pot_kwargs = {}\n",
    "pot_kwargs['status'] = 'all'\n",
    "#pot_kwargs['id'] = pot_ids[15:]\n",
    "#pot_kwargs['id'] = ['2021--Wang-G--Au-Rh--LAMMPS--ipr1']\n",
    "#pot_kwargs['pair_style'] = ['eam', 'eam/alloy', 'eam/fs', 'eam/cd']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A1--Cu--fcc\n",
      "Preparing surface_energy_static\n",
      "20505 existing calculation records found\n",
      "332 matching interatomic potentials found\n",
      "440 matching atomic parents found\n",
      "13 matching defects\n",
      "5720 record combinations to check\n",
      "1755 new records to prepare\n",
      "\n",
      "A15--beta-W\n",
      "Preparing surface_energy_static\n",
      "22261 existing calculation records found\n",
      "332 matching interatomic potentials found\n",
      "319 matching atomic parents found\n",
      "16 matching defects\n",
      "5104 record combinations to check\n",
      "1264 new records to prepare\n",
      "\n",
      "A2--W--bcc\n",
      "Preparing surface_energy_static\n",
      "23524 existing calculation records found\n",
      "332 matching interatomic potentials found\n",
      "269 matching atomic parents found\n",
      "13 matching defects\n",
      "3497 record combinations to check\n",
      "1378 new records to prepare\n",
      "\n",
      "A3'--alpha-La--double-hcp\n",
      "Preparing surface_energy_static\n",
      "24903 existing calculation records found\n",
      "332 matching interatomic potentials found\n",
      "297 matching atomic parents found\n",
      "17 matching defects\n",
      "5049 record combinations to check\n",
      "799 new records to prepare\n",
      "\n",
      "A3--Mg--hcp\n",
      "Preparing surface_energy_static\n",
      "25702 existing calculation records found\n",
      "332 matching interatomic potentials found\n",
      "272 matching atomic parents found\n",
      "19 matching defects\n",
      "5168 record combinations to check\n",
      "1596 new records to prepare\n",
      "\n",
      "A4--C--dc\n",
      "Preparing surface_energy_static\n",
      "27300 existing calculation records found\n",
      "332 matching interatomic potentials found\n",
      "176 matching atomic parents found\n",
      "16 matching defects\n",
      "2816 record combinations to check\n",
      "1776 new records to prepare\n",
      "\n",
      "A5--beta-Sn\n",
      "Preparing surface_energy_static\n",
      "29075 existing calculation records found\n",
      "332 matching interatomic potentials found\n",
      "109 matching atomic parents found\n",
      "10 matching defects\n",
      "1090 record combinations to check\n",
      "560 new records to prepare\n",
      "\n",
      "A6--In--bct\n",
      "Preparing surface_energy_static\n",
      "29633 existing calculation records found\n",
      "332 matching interatomic potentials found\n",
      "40 matching atomic parents found\n",
      "8 matching defects\n",
      "320 record combinations to check\n",
      "72 new records to prepare\n",
      "\n",
      "A7--alpha-As\n",
      "Preparing surface_energy_static\n",
      "29707 existing calculation records found\n",
      "332 matching interatomic potentials found\n",
      "21 matching atomic parents found\n",
      "21 matching defects\n",
      "441 record combinations to check\n",
      "189 new records to prepare\n",
      "\n",
      "Ah--alpha-Po--sc\n",
      "Preparing surface_energy_static\n",
      "29894 existing calculation records found\n",
      "332 matching interatomic potentials found\n",
      "148 matching atomic parents found\n",
      "13 matching defects\n",
      "1924 record combinations to check\n",
      "1235 new records to prepare\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "\n",
    "# Prepare by each family (much faster)\n",
    "for family in families:\n",
    "    print(family)\n",
    "    global_kwargs['parent_family'] = global_kwargs['defect_family'] = family\n",
    "    kwargs = deepcopy(global_kwargs)\n",
    "    for key in pot_kwargs:\n",
    "        kwargs[f'parent_potential_{key}'] = pot_kwargs[key]\n",
    "    try:\n",
    "        prepare.surface_energy_static.main(database_name, run_directory_name, **kwargs)\n",
    "    except:\n",
    "        print('0 record combinations to check')\n",
    "    \n",
    "# Fix LAMMPS versions if needed\n",
    "fix_lammps_versions(run_directory_name, commands)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.2 Stacking Faults"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = 'master_8'\n",
    "num_runners = 1\n",
    "np_per_runner = default_np_per_runner\n",
    "run_location = default_run_location\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Set commands for this machine\n",
    "global_kwargs['lammps_command'] = allcommands[run_location]['lammps_command']\n",
    "if np_per_runner > 1:\n",
    "    global_kwargs['mpi_command'] = allcommands[run_location]['mpi_command'].format(np_per_runner=np_per_runner)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "global_kwargs['parent_method'] = 'dynamic'\n",
    "global_kwargs['parent_standing'] = 'good'\n",
    "\n",
    "# Prototype families to generate defects for\n",
    "database = iprPy.load_database(database_name)\n",
    "families = np.unique(database.get_records_df(style='stacking_fault').family)\n",
    "\n",
    "# Potential-based modifiers\n",
    "pot_kwargs = {}\n",
    "pot_kwargs['status'] = 'all'\n",
    "#pot_kwargs['id'] = pot_ids[15:]\n",
    "pot_kwargs['id'] = ['1999--Mishin-Y--Al--LAMMPS--ipr1']\n",
    "#pot_kwargs['pair_style'] = ['eam', 'eam/alloy', 'eam/fs', 'eam/cd']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A1--Cu--fcc\n",
      "Preparing stacking_fault_map_2D\n",
      "0 existing calculation records found\n",
      "2 matching defects found\n",
      "2 record combinations to check\n",
      "2 new records to prepare\n",
      "\n",
      "Starting 1 runners in master_8 for master\n",
      "Runner started with pid 17264\n",
      "No simulations left to run\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "\n",
    "# Prepare by each family (much faster)\n",
    "for family in families:\n",
    "    print(family)\n",
    "    global_kwargs['parent_family'] = global_kwargs['defect_family'] = family\n",
    "    kwargs = deepcopy(global_kwargs)\n",
    "    for key in pot_kwargs:\n",
    "        kwargs[f'parent_potential_{key}'] = pot_kwargs[key]\n",
    "    prepare.stacking_fault_map_2D.main(database_name, run_directory_name, **kwargs)\n",
    "    break\n",
    "\n",
    "# Fix LAMMPS versions if needed\n",
    "fix_lammps_versions(run_directory_name, commands)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.3 Dislocation monopoles"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = 'master_7'\n",
    "num_runners = 0\n",
    "np_per_runner = default_np_per_runner\n",
    "run_location = default_run_location\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Set commands for this machine\n",
    "global_kwargs['lammps_command'] = allcommands[run_location]['lammps_command']\n",
    "if np_per_runner > 1:\n",
    "    global_kwargs['mpi_command'] = allcommands[run_location]['mpi_command'].format(np_per_runner=np_per_runner)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "#global_kwargs['parent_strainrange'] = 1e-8\n",
    "\n",
    "# Potential-based modifiers\n",
    "pot_kwargs = {}\n",
    "pot_kwargs['status'] = 'all'\n",
    "#pot_kwargs['id'] = pot_ids[15:]\n",
    "pot_kwargs['id'] = ['2006--Chamati-H--Fe--LAMMPS--ipr1']\n",
    "#pot_kwargs['pair_style'] = ['eam', 'eam/alloy', 'eam/fs', 'eam/cd']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing dislocation_monopole\n",
      "2 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "552 matching atomic archives found\n",
      "1 matching defects\n",
      "2 record combinations to check\n",
      "0 new records to prepare\n",
      "\n",
      "Preparing dislocation_monopole\n",
      "2 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "552 matching atomic archives found\n",
      "1 matching defects\n",
      "2 record combinations to check\n",
      "2 new records to prepare\n",
      "\n",
      "Preparing dislocation_monopole\n",
      "4 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "552 matching atomic archives found\n",
      "1 matching defects\n",
      "2 record combinations to check\n",
      "2 new records to prepare\n",
      "\n",
      "Preparing dislocation_monopole\n",
      "6 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "615 matching atomic archives found\n",
      "1 matching defects\n",
      "2 record combinations to check\n",
      "2 new records to prepare\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "\n",
    "# Prepare bcc screw    \n",
    "kwargs = deepcopy(global_kwargs)\n",
    "for key in pot_kwargs:\n",
    "    kwargs[f'parent_potential_{key}'] = pot_kwargs[key]\n",
    "prepare.dislocation_monopole.bcc_screw(database_name, run_directory_name, **kwargs)\n",
    "prepare.dislocation_monopole.bcc_edge(database_name, run_directory_name, **kwargs)\n",
    "prepare.dislocation_monopole.bcc_edge_112(database_name, run_directory_name, **kwargs)\n",
    "prepare.dislocation_monopole.fcc_edge_100(database_name, run_directory_name, **kwargs)\n",
    "\n",
    "# Fix LAMMPS versions if needed\n",
    "fix_lammps_versions(run_directory_name, commands)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.4 Dislocation arrays"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Database settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify database settings to use for the calculation\n",
    "database_name = default_database_name\n",
    "run_directory_name = 'master_7'\n",
    "num_runners = 0\n",
    "np_per_runner = default_np_per_runner\n",
    "run_location = default_run_location\n",
    "\n",
    "# Generic settings\n",
    "global_kwargs = {}\n",
    "\n",
    "# Set commands for this machine\n",
    "global_kwargs['lammps_command'] = allcommands[run_location]['lammps_command']\n",
    "if np_per_runner > 1:\n",
    "    global_kwargs['mpi_command'] = allcommands[run_location]['mpi_command'].format(np_per_runner=np_per_runner)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculation settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set other generic settings\n",
    "#global_kwargs['parent_strainrange'] = 1e-8\n",
    "\n",
    "# Potential-based modifiers\n",
    "pot_kwargs = {}\n",
    "pot_kwargs['status'] = 'all'\n",
    "#pot_kwargs['id'] = pot_ids[15:]\n",
    "pot_kwargs['id'] = ['2006--Chamati-H--Fe--LAMMPS--ipr1']\n",
    "#pot_kwargs['pair_style'] = ['eam', 'eam/alloy', 'eam/fs', 'eam/cd']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare and run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing dislocation_periodic_array\n",
      "4 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "615 matching atomic archives found\n",
      "1 matching defects\n",
      "2 record combinations to check\n",
      "0 new records to prepare\n",
      "\n",
      "Preparing dislocation_periodic_array\n",
      "4 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "615 matching atomic archives found\n",
      "1 matching defects\n",
      "2 record combinations to check\n",
      "0 new records to prepare\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Initialize pool of workers\n",
    "if num_runners > 1:\n",
    "    pool = Pool(num_runners)\n",
    "else:\n",
    "    pool = None\n",
    "\n",
    "# Prepare bcc screw    \n",
    "kwargs = deepcopy(global_kwargs)\n",
    "for key in pot_kwargs:\n",
    "    kwargs[f'parent_potential_{key}'] = pot_kwargs[key]\n",
    "prepare.dislocation_periodic_array.fcc_edge_mix(database_name, run_directory_name, **kwargs)\n",
    "prepare.dislocation_periodic_array.fcc_screw(database_name, run_directory_name, **kwargs)\n",
    "\n",
    "# Fix LAMMPS versions if needed\n",
    "fix_lammps_versions(run_directory_name, commands)\n",
    "\n",
    "# Run\n",
    "multi_runners(database_name, run_directory_name, num_runners, pool=pool)\n",
    "\n",
    "# Close pool\n",
    "if pool is not None:\n",
    "    pool.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
